#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
using namespace std;
const int N=3*1e3+10;

vector<pair<int,int>> edge[N];

int dist[N];
struct cmp{
	bool operator()(const pair<int,int>& p1,const pair<int,int>& p2)
	{
		return p1.second>p2.second;
	}
};
void dijkstra(int u)
{
	memset(dist,0x3f3f3f3f,sizeof(dist));
	dist[u]=0;
	priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
	q.push({u,0});
	while(q.size())
	{
		int r=q.top().first;
		int step=q.top().second;
		q.pop();
		for(auto& e:edge[r])
		{
			if(dist[e.first]>dist[r]+e.second)
			{
				dist[e.first]=dist[r]+e.second;
				q.push({e.first,dist[e.first]});
			}
		}
	}
}
int main()
{
	
	
	
	int t,c,ts,te;
	cin>>t>>c>>ts>>te;
	
	for(int i=0;i<c;i++)
	{
		int rs,re,ci;
		scanf("%d%d%d",&rs,&re,&ci);
		edge[rs].push_back({re,ci});
		edge[re].push_back({rs,ci});		
	}
	dijkstra(ts);
	cout<<dist[te]<<endl;
	return 0;
}
